package string;

public class StringDemo {
    public static void main(String[] args) {
        String s1="123abc";//字面量创建的字符串第一次使用时会缓存在常量池中
        String s2="123abc";//重用s1
        System.out.println(s1==s2);
        String s3="123abc";
        System.out.println(s3==s1);
        String s4=new String("123abc");
        System.out.println(s4==s1);
        s1=s1+"!";
        System.out.println(s1==s3);
        String s5="123"+"abc";
        System.out.println(s5==s2);
        String s="123";
        String s6=s+"abc";
        System.out.println(s2==s6);
        //比较字符串用equals()
        String s7="123abc";
        String s8=new String("123abc");
        System.out.println(s7==s8);
        System.out.println(s7.equals(s8));
    }
}
